package com.pocketsweet.service;

import java.util.List;

import com.pocketsweet.MLApplication;
import com.pocketsweet.ui.Main;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.ComponentName;
import android.content.Context;
import android.text.TextUtils;


public class NotifyService {

	public static boolean isMainActivityShowing() {
		if (MLApplication.getInstance() != null) {
			ActivityManager am = (ActivityManager) MLApplication.getContext()
					.getSystemService(Context.ACTIVITY_SERVICE);
			List<RunningTaskInfo> list = am.getRunningTasks(1);
			RunningTaskInfo cinfo = list.get(0);
			ComponentName component = cinfo.topActivity;
			if (TextUtils
					.equals(component.getClassName(), Main.class.getName())) {
				return true;
			}
		}
		return false;
	}

	public static boolean isAPPRunning() {
		ActivityManager am = (ActivityManager) MLApplication.getContext()
				.getSystemService(Context.ACTIVITY_SERVICE);
		List<RunningTaskInfo> list = am.getRunningTasks(100);
		for (RunningTaskInfo info : list) {
			if (info.topActivity.getPackageName().equals("com.pocketsweet")
					&& info.baseActivity.getPackageName().equals(
							"com.pocketsweet")) {
				return true;
			}
		}
		return false;
	}

	/*
	 * 刷新未读的NewAppler数目
	 */
	public static void refreshUnreadNum() {
		// if (isMainActivityShowing()) {
		// Main.getInstance().refreshUnReadApplerNum();
		// }
		// Find.getInstance().refreshApplier();
	}
}
